@@ -7,13 +7,16 @@ from django_logit import logit |
||
| 7 | 7 |
from django_response import response |
| 8 | 8 |
|
| 9 | 9 |
from integral.models import SaleclerkIntegralIncomeExpensesInfo, SaleclerkSubmitLogInfo |
| 10 |
-from mch.models import BrandInfo, DistributorInfo, ModelInfo, SaleclerkInfo |
|
| 10 |
+from mch.models import BrandInfo, DistributorInfo, ModelInfo, SaleclerkInfo, ConsumeInfoSubmitLogInfo, ActivityInfo |
|
| 11 | 11 |
from staff.models import StaffDeleteClerkSaleSubmitLogInfo |
| 12 |
+from coupon.models import CouponInfo, UserCouponInfo |
|
| 13 |
+from account.models import UserInfo |
|
| 14 |
+from member.models import RightInfo |
|
| 12 | 15 |
from statistic.models import (DistributorSaleStatisticInfo, ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, |
| 13 |
- SaleclerkSaleStatisticInfo, SaleStatisticInfo) |
|
| 16 |
+ SaleclerkSaleStatisticInfo, SaleStatisticInfo, ConsumeSaleStatisticInfo, ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo, ConsumeProvinceSaleStatisticInfo, ConsumeUserStatisticInfo) |
|
| 14 | 17 |
|
| 15 | 18 |
|
| 16 |
-def exec_del_clerk_sale_submit(pk, username): |
|
| 19 |
+def exec_del_clerk_sale_submit(pk): |
|
| 17 | 20 |
try: |
| 18 | 21 |
ssli = SaleclerkSubmitLogInfo.objects.select_for_update().get(pk=pk) |
| 19 | 22 |
except SaleclerkSubmitLogInfo.DoesNotExist: |
@@ -22,19 +25,10 @@ def exec_del_clerk_sale_submit(pk, username): |
||
| 22 | 25 |
if not ssli.status: |
| 23 | 26 |
return response() |
| 24 | 27 |
|
| 25 |
- if ssli.is_staff_delete: |
|
| 26 |
- return response() |
|
| 27 |
- |
|
| 28 |
- sn = ssli.code |
|
| 29 |
- |
|
| 30 |
- StaffDeleteClerkSaleSubmitLogInfo.objects.create(username=username, code=sn) |
|
| 31 |
- |
|
| 32 | 28 |
ssli.status = False |
| 33 | 29 |
ssli.is_staff_delete = True |
| 34 | 30 |
ssli.save() |
| 35 | 31 |
|
| 36 |
- SaleclerkIntegralIncomeExpensesInfo.objects.select_for_update().filter(code=sn).update(status=False) |
|
| 37 |
- |
|
| 38 | 32 |
try: |
| 39 | 33 |
brand = BrandInfo.objects.get(pk=ssli.brand_pk) |
| 40 | 34 |
except BrandInfo.DoesNotExist: |
@@ -210,12 +204,234 @@ def exec_del_clerk_sale_submit(pk, username): |
||
| 210 | 204 |
|
| 211 | 205 |
|
| 212 | 206 |
@logit |
| 213 |
-@staff_member_required |
|
| 214 | 207 |
@transaction.atomic |
| 215 | 208 |
def del_clerk_sale_submit_api(request): |
| 216 |
- brand_id = request.GET.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
|
|
| 217 |
- pk = request.GET.get('pk', '')
|
|
| 209 |
+ brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
|
|
| 210 |
+ pk = int(request.POST.get('pk', ''))
|
|
| 211 |
+ |
|
| 212 |
+ exec_del_clerk_sale_submit(pk) |
|
| 213 |
+ |
|
| 214 |
+ return response(200, 'Del Success', u'删除成功') |
|
| 215 |
+ |
|
| 216 |
+def exec_del_consumer_submit(pk): |
|
| 217 |
+ try: |
|
| 218 |
+ ssli = ConsumeInfoSubmitLogInfo.objects.select_for_update().get(pk=pk) |
|
| 219 |
+ except ConsumeInfoSubmitLogInfo.DoesNotExist: |
|
| 220 |
+ return response() |
|
| 221 |
+ |
|
| 222 |
+ if not ssli.status: |
|
| 223 |
+ return response() |
|
| 224 |
+ |
|
| 225 |
+ sn = ssli.serialNo |
|
| 226 |
+ |
|
| 227 |
+ ssli.status = False |
|
| 228 |
+ ssli.save() |
|
| 229 |
+ |
|
| 230 |
+ ConsumeInfoSubmitLogInfo.objects.filter(serialNo=sn, model_id=ssli.model_id, dupload=True, status=True).update(status=False) |
|
| 231 |
+ |
|
| 232 |
+ if ssli.dupload: |
|
| 233 |
+ return response() |
|
| 234 |
+ |
|
| 235 |
+ try: |
|
| 236 |
+ brand = BrandInfo.objects.get(brand_id=ssli.brand_id) |
|
| 237 |
+ except BrandInfo.DoesNotExist: |
|
| 238 |
+ return response() |
|
| 239 |
+ |
|
| 240 |
+ try: |
|
| 241 |
+ model = ModelInfo.objects.get(model_id=ssli.model_id) |
|
| 242 |
+ except ModelInfo.DoesNotExist: |
|
| 243 |
+ return response() |
|
| 244 |
+ |
|
| 245 |
+ try: |
|
| 246 |
+ user = UserInfo.objects.select_for_update().get(user_id=ssli.user_id) |
|
| 247 |
+ except UserInfo.DoesNotExist: |
|
| 248 |
+ return response() |
|
| 249 |
+ |
|
| 250 |
+ #消除用户劵 |
|
| 251 |
+ if user.shots_num <= 5: |
|
| 252 |
+ rights = RightInfo.objects.filter(is_send_coupon=True, status=True) |
|
| 253 |
+ for right in rights: |
|
| 254 |
+ if user.level == UserInfo.MEMBER_LRC: |
|
| 255 |
+ coupon_id = right.coupon_level1_id |
|
| 256 |
+ coupon_num = right.coupon_level1_num |
|
| 257 |
+ elif user.level == UserInfo.MEMBER_SILVER: |
|
| 258 |
+ coupon_id = right.coupon_level2_id |
|
| 259 |
+ coupon_num = right.coupon_level2_num |
|
| 260 |
+ elif user.level == UserInfo.MEMBER_GOLD: |
|
| 261 |
+ coupon_id = right.coupon_level3_id |
|
| 262 |
+ coupon_num = right.coupon_level3_num |
|
| 263 |
+ elif user.level == UserInfo.MEMBER_WHITE_GOLD: |
|
| 264 |
+ coupon_id = right.coupon_level4_id |
|
| 265 |
+ coupon_num = right.coupon_level4_num |
|
| 266 |
+ elif user.level == UserInfo.MEMBER_BLACK_GOLD: |
|
| 267 |
+ coupon_id = right.coupon_level5_id |
|
| 268 |
+ coupon_num = right.coupon_level5_num |
|
| 269 |
+ else: |
|
| 270 |
+ continue |
|
| 271 |
+ |
|
| 272 |
+ try: |
|
| 273 |
+ coupon = CouponInfo.objects.get(coupon_id=coupon_id) |
|
| 274 |
+ except CouponInfo.DoesNotExist: |
|
| 275 |
+ continue |
|
| 276 |
+ |
|
| 277 |
+ user_coupons = UserCouponInfo.objects.filter(user_id=user.user_id, coupon_id=coupon_id, coupon_from='MEMBER_BENEFITS', status=True, has_used=False).values_list('pk', flat=True)
|
|
| 278 |
+ # 防止用户部分劵已使用,不够消除 |
|
| 279 |
+ UserCouponInfo.objects.filter(pk__in=list(user_coupons)[0:min(coupon_num, len(user_coupons))]).update(status=False) |
|
| 280 |
+ |
|
| 281 |
+ # 消除活动劵 |
|
| 282 |
+ if ssli.submit_during_activity: |
|
| 283 |
+ UserCouponInfo.objects.filter(user_id=user.user_id, coupon_from='PROMOTION', submit_pk=ssli.pk).update(status=False) |
|
| 284 |
+ |
|
| 285 |
+ #消除积分及会员等级 |
|
| 286 |
+ integral = model.shot_member_integral |
|
| 287 |
+ |
|
| 288 |
+ if user.shots_num <= 5: |
|
| 289 |
+ user.level -= 1 |
|
| 290 |
+ user.shots_num -= 1 |
|
| 291 |
+ user.integral -= integral |
|
| 292 |
+ user.integral = max(user.integral, 0) |
|
| 293 |
+ user.save() |
|
| 294 |
+ |
|
| 295 |
+ # 消除统计记录 |
|
| 296 |
+ |
|
| 297 |
+ ymd = str(ssli.ymd) |
|
| 298 |
+ |
|
| 299 |
+ if not user.test_user: |
|
| 300 |
+ # 日销量统计 |
|
| 301 |
+ ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 302 |
+ brand_id=brand.brand_id, |
|
| 303 |
+ ymd=ymd, |
|
| 304 |
+ ) |
|
| 305 |
+ ssi.num -= 1 |
|
| 306 |
+ ssi.save() |
|
| 307 |
+ # 月销量统计 |
|
| 308 |
+ ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 309 |
+ brand_id=brand.brand_id, |
|
| 310 |
+ ymd=ymd[:6], |
|
| 311 |
+ ) |
|
| 312 |
+ ssi.num -= 1 |
|
| 313 |
+ ssi.save() |
|
| 314 |
+ # 年销量统计 |
|
| 315 |
+ ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 316 |
+ brand_id=brand.brand_id, |
|
| 317 |
+ ymd=ymd[:4], |
|
| 318 |
+ ) |
|
| 319 |
+ ssi.num -= 1 |
|
| 320 |
+ ssi.save() |
|
| 321 |
+ |
|
| 322 |
+ |
|
| 323 |
+ # 日用户统计 |
|
| 324 |
+ ussi, _ = ConsumeUserStatisticInfo.objects.select_for_update().get_or_create( |
|
| 325 |
+ brand_id=brand.brand_id, |
|
| 326 |
+ ymd=ymd, |
|
| 327 |
+ ) |
|
| 328 |
+ try: |
|
| 329 |
+ ussi.users.remove(user.user_id) |
|
| 330 |
+ except ValueError: |
|
| 331 |
+ pass |
|
| 332 |
+ ussi.num = len(ussi.users) |
|
| 333 |
+ ussi.save() |
|
| 334 |
+ |
|
| 335 |
+ # 月用户统计 |
|
| 336 |
+ ussi, _ = ConsumeUserStatisticInfo.objects.select_for_update().get_or_create( |
|
| 337 |
+ brand_id=brand.brand_id, |
|
| 338 |
+ ymd=ymd[:6], |
|
| 339 |
+ ) |
|
| 340 |
+ try: |
|
| 341 |
+ ussi.users.remove(user.user_id) |
|
| 342 |
+ except ValueError: |
|
| 343 |
+ pass |
|
| 344 |
+ ussi.num = len(ussi.users) |
|
| 345 |
+ ussi.save() |
|
| 346 |
+ |
|
| 347 |
+ # 年用户统计 |
|
| 348 |
+ ussi, _ = ConsumeUserStatisticInfo.objects.select_for_update().get_or_create( |
|
| 349 |
+ brand_id=brand.brand_id, |
|
| 350 |
+ ymd=ymd[:4], |
|
| 351 |
+ ) |
|
| 352 |
+ try: |
|
| 353 |
+ ussi.users.remove(user.user_id) |
|
| 354 |
+ except ValueError: |
|
| 355 |
+ pass |
|
| 356 |
+ ussi.num = len(ussi.users) |
|
| 357 |
+ ussi.save() |
|
| 358 |
+ |
|
| 359 |
+ # 型号日销量统计 |
|
| 360 |
+ mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 361 |
+ brand_id=brand.brand_id, |
|
| 362 |
+ model_name=model.model_uni_name, |
|
| 363 |
+ ymd=ymd, |
|
| 364 |
+ ) |
|
| 365 |
+ try: |
|
| 366 |
+ mssi.users.remove(user.user_id) |
|
| 367 |
+ except ValueError: |
|
| 368 |
+ pass |
|
| 369 |
+ mssi.num = len(mssi.users) |
|
| 370 |
+ mssi.save() |
|
| 371 |
+ |
|
| 372 |
+ # 型号月销量统计 |
|
| 373 |
+ mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 374 |
+ brand_id=brand.brand_id, |
|
| 375 |
+ model_name=model.model_uni_name, |
|
| 376 |
+ ymd=ymd[:6], |
|
| 377 |
+ ) |
|
| 378 |
+ try: |
|
| 379 |
+ mssi.users.remove(user.user_id) |
|
| 380 |
+ except ValueError: |
|
| 381 |
+ pass |
|
| 382 |
+ mssi.num = len(mssi.users) |
|
| 383 |
+ mssi.save() |
|
| 384 |
+ |
|
| 385 |
+ # 型号年销量统计 |
|
| 386 |
+ mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 387 |
+ brand_id=brand.brand_id, |
|
| 388 |
+ model_name=model.model_uni_name, |
|
| 389 |
+ ymd=ymd[:4], |
|
| 390 |
+ ) |
|
| 391 |
+ try: |
|
| 392 |
+ mssi.users.remove(user.user_id) |
|
| 393 |
+ except ValueError: |
|
| 394 |
+ pass |
|
| 395 |
+ mssi.num = len(mssi.users) |
|
| 396 |
+ mssi.save() |
|
| 397 |
+ |
|
| 398 |
+ # 省份日销量统计 |
|
| 399 |
+ pssi, _ = ProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 400 |
+ brand_id=brand.brand_id, |
|
| 401 |
+ province_name=ssli.province, |
|
| 402 |
+ ymd=ymd, |
|
| 403 |
+ ) |
|
| 404 |
+ pssi.province_name = ssli.province |
|
| 405 |
+ pssi.num -= 1 |
|
| 406 |
+ pssi.save() |
|
| 407 |
+ |
|
| 408 |
+ # 省份月销量统计 |
|
| 409 |
+ pssi, _ = ProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 410 |
+ brand_id=brand.brand_id, |
|
| 411 |
+ province_name=ssli.province, |
|
| 412 |
+ ymd=ymd[:6], |
|
| 413 |
+ ) |
|
| 414 |
+ pssi.province_name = ssli.province |
|
| 415 |
+ pssi.num -= 1 |
|
| 416 |
+ pssi.save() |
|
| 417 |
+ |
|
| 418 |
+ # 省份年销量统计 |
|
| 419 |
+ pssi, _ = ProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
| 420 |
+ brand_id=brand.brand_id, |
|
| 421 |
+ province_name=ssli.province, |
|
| 422 |
+ ymd=ymd[:4], |
|
| 423 |
+ ) |
|
| 424 |
+ pssi.province_name = ssli.province |
|
| 425 |
+ pssi.num -= 1 |
|
| 426 |
+ pssi.save() |
|
| 427 |
+ |
|
| 428 |
+ |
|
| 429 |
+@logit |
|
| 430 |
+@transaction.atomic |
|
| 431 |
+def del_consumer_submit_api(request): |
|
| 432 |
+ brand_id = request.POST.get('brand_id', settings.KODO_DEFAULT_BRAND_ID)
|
|
| 433 |
+ pk = int(request.POST.get('pk', ''))
|
|
| 218 | 434 |
|
| 219 |
- exec_del_clerk_sale_submit(pk, request.user.username) |
|
| 435 |
+ exec_del_consumer_submit(pk) |
|
| 220 | 436 |
|
| 221 | 437 |
return response(200, 'Del Success', u'删除成功') |
@@ -369,4 +369,5 @@ urlpatterns += [ |
||
| 369 | 369 |
|
| 370 | 370 |
urlpatterns += [ |
| 371 | 371 |
url(r'^del/clerk/sale/submit$', staff_views.del_clerk_sale_submit_api, name='del_clerk_sale_submit_api'), |
| 372 |
+ url(r'^del/consumer/submit$', staff_views.del_consumer_submit_api, name='del_consumer_submit_api'), |
|
| 372 | 373 |
] |